package com.example.administrator.waitan.find;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.tools.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/13.
 */
public class LookWeekRecyclerViewAdapter extends RecyclerView.Adapter<LookWeekRecyclerViewAdapter.MyViewHolder>{
    private Context context;
    private List<LookWeekInfo> data;
    private ImageLoader imageLoader;
    private ImageLoader.ImageCache imageCache;
    private LruCache<String,Bitmap> lruCache;
    private RequestQueue queue;
    public LookWeekRecyclerViewAdapter(Context context, List<LookWeekInfo> data) {
        this.context = context;
        this.data = data;
//        init();
    }
//    private void init() {
//        queue = Volley.newRequestQueue(context);
//        lruCache = new LruCache<String,Bitmap>(20);
//        imageCache = new ImageLoader.ImageCache() {
//            @Override
//            public Bitmap getBitmap(String url) {
//                return lruCache.get(url);
//            }
//
//            @Override
//            public void putBitmap(String url, Bitmap bitmap) {
//                lruCache.put(url,bitmap);
//            }
//        };
//        imageLoader = new ImageLoader(queue,imageCache);
//    }
//    public void getBitmapCache(String imgUrl, ImageView imageView){
//        ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView,R.mipmap.mi_icon,R.mipmap.mi_icon);
//        imageLoader.get(imgUrl,listener,600,600);
//    }

    @Override
    public LookWeekRecyclerViewAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_rc_lookweek,parent,false);
       MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.date.setText(data.get(position).getDate());
//        String imgurl = data.get(position).getThumbnail();
//        getBitmapCache(imgurl,holder.pic);
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(holder.pic,R.mipmap.mi_icon,R.mipmap.mi_icon);
        VolleySingleton.getImageLoader().get(data.get(position).getThumbnail(),listener);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView date;ImageView pic;
        public MyViewHolder(View itemView) {
            super(itemView);
            date = (TextView) itemView.findViewById(R.id.tv_item_lookWeek_title);
            pic = (ImageView) itemView.findViewById(R.id.iv_item_lookWeek_pic);
        }
    }
}
